package com.yunji.cabinet.service.impl;

import com.yunji.cabinet.dao.IContainerTypeDao;
import com.yunji.cabinet.domain.ContainerTypeDO;
import com.yunji.common.exception.ServiceException;
import com.yunji.common.model.cache.ContainerTypeCacheDTO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class CabinetBaseService {
    @Resource
    private IContainerTypeDao containerTypeDao;


    public List<ContainerTypeDO> typeList() {
        return containerTypeDao.list();
    }

    //FIXME 这里需要缓存
    public ContainerTypeCacheDTO getTypeCacheById(String code) {
        ContainerTypeDO byId = containerTypeDao.getById(code);
        ServiceException.throwException(byId == null, "货柜类型不能为空,请严格检查货柜imei存不存在,不要乱提BUG");
        ContainerTypeCacheDTO cache = new ContainerTypeCacheDTO();
        BeanUtils.copyProperties(byId, cache);
        return cache;
    }

    public ContainerTypeDO getTypeById(String code) {
        return containerTypeDao.getById(code);
    }

    public String createType(ContainerTypeDO domain) {
        containerTypeDao.save(domain);
        return domain.getTypeCode();
    }

    public void updateType(ContainerTypeDO domain) {
        containerTypeDao.updateById(domain);
    }

    public void deleteType(Long id) {
        containerTypeDao.removeById(id);
    }


//    public List<ContainerShapeDO> shapeList() {
//        return cabinetShapeDao.list();
//    }
//
//    //FIXME 这里需要缓存
//    public ContainerShapeDO getShapeCacheById(Integer id) {
//        return cabinetShapeDao.getById(id);
//    }
//
//    public Integer createShape(ContainerShapeDO shape) {
//        cabinetShapeDao.save(shape);
//        return shape.getShapeId();
//    }
//
//
//    public void updateShape(ContainerShapeDO shape) {
//        cabinetShapeDao.updateById(shape);
//    }
//
//
//    public void deleteShape(Long shapeId) {
//        cabinetShapeDao.removeById(shapeId);
//    }
//
//    public ContainerShapeDO getShapeById(Long id) {
//        return cabinetShapeDao.getById(id);
//    }
}
